package com.betterjr.modules.risk.loan.dao;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

import com.betterjr.common.utils.Collections3;
import com.betterjr.modules.customer.entity.CustMechBankAccount;
import com.betterjr.modules.risk.loan.data.LoanProjectRelationConstantCollections;
import com.betterjr.modules.risk.loan.entity.LoanProjectBank;
import com.betterjr.modules.risk.loan.entity.LoanProjectRelation;
import com.google.common.collect.Lists;

public abstract class FillBankAbstract {

    public abstract boolean fillBank(LoanProjectRelation anLoan, LoanProjectBank anBank);

    protected List<CustMechBankAccount> getBankAccount(List<CustMechBankAccount> banks, String bankIds) {

        if (!Collections3.isEmpty(banks) && StringUtils.isNoneBlank(bankIds)) {

            List<CustMechBankAccount> newBanks = new ArrayList<CustMechBankAccount>();

            Set<String> ids = new HashSet<>(
                    Arrays.asList(bankIds.split(LoanProjectRelationConstantCollections.FILE_DATA_SEPATORY_CHAR)));

            for (CustMechBankAccount custMechBankAccount : banks) {
                if (ids.contains(custMechBankAccount.getId() + "")) {
                    newBanks.add(custMechBankAccount);
                }
            }

            return newBanks;

        }

        return Lists.newArrayList();
    }

    public abstract void fillBank(LoanProjectRelation anLoan, List<CustMechBankAccount> accountList);
}
